﻿package core.dialog {
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.text.TextField;
	import 	flash.events.MouseEvent;
	import core.events.MessageDialogEvent;
	import core.display.AlphaBg;
	import base.BaseMc;
	
	
	public class DialogMessage extends BaseMc {
	

		private var titleText:String;
		private var infoText:String;
		private var isSingleButtonType:Boolean;
		private var bg:AlphaBg;
		
		public function DialogMessage(infoText: String , isSingleButtonType: Boolean,titleText: String = "提示") {
			this.titleText = titleText;
			this.infoText = infoText;
			this.isSingleButtonType =isSingleButtonType;
		}
		
		protected override function onInit():void {
			bg = new AlphaBg();
			this.parent.addChild(bg);
			this.parent.swapChildren(bg,this);
			//trace("DialogMessage onInit");
			this.initComponent();
			//trace(this.width);
			//trace(this.height);
			this.scale(1.5,1.5);
			this.x = (this.stage.stageWidth - this.width) / 2;
			this.y = (this.stage.stageHeight - this.height) / 2;
		}
		
		protected override function onRemove():void {
			this.btCancel.removeEventListener(MouseEvent.CLICK,btCancelClick);
			this.btOk.removeEventListener(MouseEvent.CLICK,btOkClick);
			this.btCenter.removeEventListener(MouseEvent.CLICK,btOkClick);
			this.parent.removeChild(bg);
		}
		
		private  function initComponent():void {
			if(titleText){
				this.titleField.text =titleText;
			}
			
			if(infoText){
				this.infoField.text = infoText;
			}
			
			if(isSingleButtonType){
				this.btOk.parent.removeChild(btOk);
				this.btCancel.parent.removeChild(btCancel);
			}else{
				this.btCenter.parent.removeChild(btCenter);
			}
			
			
			this.btCancel.addEventListener(MouseEvent.CLICK,btCancelClick);
			this.btOk.addEventListener(MouseEvent.CLICK,btOkClick);
			this.btCenter.addEventListener(MouseEvent.CLICK,btOkClick);
		}
		
		
		private  function btCancelClick(e:MouseEvent):void {
			this.parent.removeChild(this);
			dispatchEvent(new MessageDialogEvent(MessageDialogEvent.CANCEL,"cancel"));
		}
		
		
		
		private  function btOkClick(e:MouseEvent):void {
			this.parent.removeChild(this);
			dispatchEvent(new MessageDialogEvent(MessageDialogEvent.OK,"ok"));
		}
		
		

		
	}
}